<?php
$isReloadable = true;
require_once("../../../pers/inc.config.php");
require_once('../../_inc/inc.session.php');
require_once('../../_inc/funct.html.php');
require_once('../../_inc/funct.tabDati.php');

if (reqVar('azione') == 'elimina') {
	$msgPag .= confElim();
} 
$sqlSel = "SELECT * FROM rgl_mod_rglob " .
		" WHERE id_mod_rglob = ".intval(reqVar('id'));
$objDB->query($sqlSel,'selRec');
if (!$acRec = $objDB->fetch('selRec')) {
	backOnErr("modRglobVis id. '".reqVar('id')."' mancante o errato ".$sqlSel);
}
$_REQUEST = array_merge($acRec,$_REQUEST);
$aPuntMbil = array(20=>'C',30=>'CC',40=>'CCC',50=>'B',60=>'BB',70=>'BBB',80=>'A',90=>'AA',100=>'AAA');
$sSql = "SELECT p.*  FROM rgl_puntglob p WHERE id_mod_rglob = ".reqVar('id')
	." ORDER BY p.punteggio ";
$objDB->query($sSql,'tdatiInp');
while($aP=$objDB->fetch('tdatiInp')) {
	$pX = $aP['punteggio'];
	reqDef('pglo_sigla_'.$pX,$aP['sigla']);
	reqDef('pglo_desbr_'.$pX,$aP['descr']);
	reqDef('pglo_deses_'.$pX,$aP['descr_estesa']);
	reqDef('pglo_color_'.$pX,$aP['colore']);	
}
foreach($aPuntMbil as $pX => $cX) {
	reqDef('pglo_sigla_'.$pX,$cX);
	reqDef('pglo_desbr_'.$pX,'');
	reqDef('pglo_deses_'.$pX,'');
	reqDef('pglo_color_'.$pX,'rosso');		
}

$cmdL = "";
$cmdL .= "&nbsp;&nbsp;&nbsp;";
//$cmdL .= "<a class='cmd1' href='parIndSettList.php?id=".reqVar('id')."&$sXSNQS' >soglie settoriali</a>";

$sCmdPagR = '';
if (true) {
	$sCmdPagR .= "&nbsp;&nbsp;&nbsp;";
	//$sCmdPagR .= "<a class='cmd1' href='datoIns.php?id=".reqVar('id')."&$sXSNQS' >nuovo dato</a>";
	//$sCmdPagR .= "&nbsp;&nbsp;&nbsp;";
	$sCmdPagR .= "<a class='cmd1' href='modRglobMod.php?id=".reqVar('id')."&$sXSNQS' >modifica</a>";
	if (true) {
		$sCmdPagR .= "&nbsp;&nbsp;&nbsp;";
		$sCmdPagR .= "<a class='cmd1' href='#' onclick='confElim();' >elimina</a>";
	}
}
$sCmdPagR .= cmdTorna(); 

testaHtml('Gestione modelli',$msgPag, 'modl');
?>
<script language="JavaScript" type="text/javascript">
  	function confElim() {
  		if (confirm("Confermi l'eliminazione del modello ?")) {
  			document.location.href = "<?=$_SERVER['PHP_SELF']."?id=".reqVar('id')."&azione=elimina&".$sXSNQS?>";
  		}
  	}
  	function clonaMrg() {
  		if (!confirm("Confermi la clonazione del modello ?")) {
  	  	  	return;
  		}
  	  	campoCod = document.getElementById('mrg_clona');
  	  	if(!campoCod) {
  	  	  	alert('123 - anomalia pagina');
  	  	  	return ;
  	  	}
  	  	document.location.href = "<?=$_SERVER['PHP_SELF']?>?id=<?=reqVar('id')?>&azione=clona&mrg_clona="
  	  	  	+encodeURI(campoCod.value)+"&xsn=<?=XSN?>";
  	}
</script>
<table class="cmd1" border="0" cellpadding="3" cellspacing="1" width="100%" align='center'>
	<?=getHtmlRigaRif(20);?>
   <tr>
      <td class="cmd1" align="left" colspan='10'>
      	<?=$cmdL?>
      </td>
      <td class="cmd1" align="right" colspan='10'><?=$sCmdPagR?></td>
   </tr>
   <tr>
      <td class="tit1" colspan='20' align='center'>Modello rating globale</td>
   </tr>
<?
$aCamForm = array();
require("_inc/const.campiModRglob.php");
// non visualizza nota vuoto
if (reqVarTrim('nota')=='') {
	foreach($aCamForm as $rr => $aX) {
		foreach($aX as $cc => $aY) {
			if ($aY[0]=='nota') {
				unset($aCamForm[$rr][$cc]);
			}
		}
	}
}
echo getHtmlCampiForm($aCamForm,'vis');
?>
   <tr>
      <td class="lab1" colspan='20' align='center'>Punteggi</td>
   </tr>
   <tr>
      <td class="lab1" colspan='2' align='center'>Soglia</td>
      <td class="lab1" colspan='2' align='center'>Sigla</td>
      <td class="lab1" colspan='12' align='center'>Descrizione breve / estesa</td>
      <td class="lab1" colspan='4' align='center'>colore</td>
   </tr>
<?
$aColorPunt = array('rosso'=>'rosso','giallo'=>'giallo','verde'=>'verde');
foreach($_REQUEST as $nX => $vX) {
	if (substr($nX,0,11)!='pglo_sigla_') continue;
	$pX = substr($nX,11);
?>
   <tr>
      <td class="txt1" colspan='2' align='right' valign='top'><?=$pX?>&nbsp;</td>
      <td class="txt1" colspan='2' align='center' valign='top'><?=getHtmlVisText('pglo_sigla_'.$pX)?></td>
      <td class="txt1" colspan='12' align='left' valign='top'>
      	<?=getHtmlVisText('pglo_desbr_'.$pX)?><br/>
      	<?=getHtmlVisNote('pglo_deses_'.$pX,80,2)?>
      </td>
      <td class="txt1" colspan='4' align='left' valign='top'>
      	&nbsp;&nbsp;&nbsp;<?=getHtmlVisDecode('pglo_color_'.$pX,$aColorPunt)?>
      </td>
   </tr>
<?
}
?>
<tr>
   <td class="cmd1" align="right" colspan='20'><?=$sCmdPagR?></td>
</tr>
</table>

<?
codaHtml();
exit();

function confElim() {
	global $objDB;
	$msg = '';
	$sSqlDel = "SELECT * FROM rgl_rating WHERE id_mod_rglob = ".intval(reqvar('id'));
	$objDB->exec($sSqlDel);
	if ($acX=$objDB->fetch()) {
		$msg .= "esistono rating - eliminazione non effettuata<br>";
	}
	if ($msg != '') {
		return $msg;
	}
	$sSqlDel = "DELETE FROM rgl_mod_rglob WHERE id_mod_rglob = ".intval(reqvar('id'));
	$objDB->exec($sSqlDel);
	backPage('modello eliminato');
	exit();
}

